package com.dl.Servlet;

import com.dl.Bean.Customer;
import com.dl.CustomerService.CustomerSerice;
import com.dl.CustomerServiceImpl.CustomerServiceImpl;
import com.dl.DaoImpl.CustomerYanzheng;
import com.dl.DaoImpl.LoginYanzhengImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/Login")
public class Login extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
        Customer cs=new Customer();
        HttpSession session= request.getSession();
        cs.setName(request.getParameter("name"));//设置javaBean数据
        cs.setPassword(request.getParameter("password"));
        LoginYanzhengImpl yanzheng=new LoginYanzhengImpl();
        session.setAttribute("cs",cs);
        try {
            if(yanzheng.dengluYanzheng(cs)==true){

                request.getRequestDispatcher("loginSuccess.jsp").forward(request, response) ;//跳转成功页面
            }else{
                System.out.println("<p>登录失败</p>");
                response.sendRedirect("main.jsp");//跳转错误页面
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
